{% extends 'generic/object_detail.html' %}
{% load helpers %}
{% load custom_links %}
{% load form_helpers %}
{% load log_levels %}
{% load plugins %}
{% load static %}

{% block header %}
    <div class="row noprint">
        <div class="col-md-12">
            <ol class="breadcrumb">
                <li><a href="{% url 'extras:jobresult_list' %}">Job Results</a></li>
                {% if associated_record and associated_record.name %}
                    <li><a href="{% url 'extras:jobresult_list' %}?name={{ associated_record.name|urlencode }}">
                        {{ associated_record.name }}
                    </a></li>
                {% elif associated_record %}
                    <li>{{ associated_record }}</li>
                {% elif job %}
                    <li><a href="{% url 'extras:jobresult_list' %}?name={{ job.class_path|urlencode }}">
                        {{ job.class_path }}
                    </a></li>
                {% else %}
                    <li>{{ result.name }}</li>
                {% endif %}
                <li>{{ result.created }}</li>
            </ol>
        </div>
    </div>
    <div class="pull-right noprint">
        {% plugin_buttons result %}
        {% if perms.extras.delete_jobresult %}
            <a href="{% url 'extras:jobresult_delete' pk=result.pk %}" class="btn btn-danger">
                <span class="mdi mdi-trash-can-outline" aria-hidden="true"></span> Delete
            </a>
        {% endif %}
    </div>
    <h1>
        {% block title %}
        {% if associated_record %}{{ associated_record }}{% elif job %}{{ job }}{% else %}{{ result.name }}{% endif %} - Job Result
        - {{ result.get_status_display }}
        {% endblock %}
    </h1>

    <div class="pull-right noprint">
        {% custom_links result %}
    </div>
    {% if job %}
        <p>{{ job.description }}</p>
    {% endif %}
    <ul class="nav nav-tabs" role="tablist">
        <li role="presentation" class="active">
            <a href="#log" role="tab" data-toggle="tab" class="active">Log</a>
        </li>
        <li role="presentation">
            <a href="#json" role="tab" data-toggle="tab">Additional Data</a>
        </li>
        {% if result.data.output %}
            <li role="presentation">
                <a href="#output" role="tab" data-toggle="tab">Output</a>
            </li>
        {% endif %}
        {% if job %}
            <li role="presentation">
                <a href="#source" role="tab" data-toggle="tab">Source</a>
            </li>
        {% endif %}
    </ul>
{% endblock %}

{% block content %}
    <div class="tab-content">
        <div role="tabpanel" class="tab-pane active" id="log">
            <div class="row noprint">
                <div class="col-md-12">
                    {% include 'extras/inc/jobresult.html' with result=result log_table=log_table %}
                </div>
            </div>
        </div>
        <div role="tabpanel" class="tab-pane" id="json">
            <div class="container-fluid">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <strong>Additional Data</strong>
                    </div>
                    <div class="panel-body">
                        {% include 'extras/inc/json_data.html' with data=result.data format="json" %}
                    </div>
                </div>
            </div>
        </div>
        {% if result.data.output %}
            <div role="tabpanel" class="tab-pane" id="output">
                <pre>{{ result.data.output }}</pre>
            </div>
        {% endif %}
        {% if job %}
            <div role="tabpanel" class="tab-pane" id="source">
                <p><code>{{ job.filename }}</code></p>
                <pre>{{ job.source }}</pre>
            </div>
        {% endif %}
    </div>
    <div class="row">
        <div class="col-md-12">
            {% plugin_full_width_page result %}
        </div>
    </div>
{% endblock %}

{% block javascript %}
    {{ block.super }}
    {% include 'extras/inc/jobresult_js.html' with result=result %}
    <script src="{% static 'js/tableconfig.js' %}?v{{ settings.VERSION }}"></script>
    <script src="{% static 'js/log_level_filtering.js' %}?v{{ settings.VERSION }}"></script>
{% endblock %}
